﻿using System;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;

namespace OracleDAL.Common
{
    public class DWS_RESOURCEITEM_INFO
    {
        /// <summary>
        /// 
        /// </summary>
        public DWS_RESOURCEITEM_INFO()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string DWS_RESOURCEID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from DWS_RESOURCEITEM_INFO");
            strSql.Append(" where DWS_RESOURCEID=:DWS_RESOURCEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":DWS_RESOURCEID", OracleType.VarChar,50)};
            parameters[0].Value = DWS_RESOURCEID;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Common.DWS_RESOURCEITEM_INFO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into DWS_RESOURCEITEM_INFO(");
            strSql.Append("DWS_RESOURCEID,DWS_RESOURCENAME,DWS_RESOURCESTATUS,RECORDTIME,DWS_REMARK,DWS_IP,DWS_DEPARTMENT,DWS_DESCRIPTION)");
            strSql.Append(" values (");
            strSql.Append(":DWS_RESOURCEID,:DWS_RESOURCENAME,:DWS_RESOURCESTATUS,:RECORDTIME,:DWS_REMARK,:DWS_IP,:DWS_DEPARTMENT,:DWS_DESCRIPTION)");
            OracleParameter[] parameters = {
					new OracleParameter(":DWS_RESOURCEID", OracleType.VarChar,100),
					new OracleParameter(":DWS_RESOURCENAME", OracleType.VarChar,800),
					new OracleParameter(":DWS_RESOURCESTATUS", OracleType.VarChar,10),
					new OracleParameter(":RECORDTIME", OracleType.DateTime),
					new OracleParameter(":DWS_REMARK", OracleType.VarChar,800),
					new OracleParameter(":DWS_IP", OracleType.VarChar,30),
					new OracleParameter(":DWS_DEPARTMENT", OracleType.VarChar,800),
					new OracleParameter(":DWS_DESCRIPTION", OracleType.VarChar,800)};
            parameters[0].Value = model.DWS_RESOURCEID;
            parameters[1].Value = model.DWS_RESOURCENAME;
            parameters[2].Value = model.DWS_RESOURCESTATUS;
            parameters[3].Value = model.RECORDTIME;
            parameters[4].Value = model.DWS_REMARK;
            parameters[5].Value = model.DWS_IP;
            parameters[6].Value = model.DWS_DEPARTMENT;
            parameters[7].Value = model.DWS_DESCRIPTION;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.Common.DWS_RESOURCEITEM_INFO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DWS_RESOURCEITEM_INFO set ");
            strSql.Append("DWS_RESOURCEID=:DWS_RESOURCEID,");
            strSql.Append("DWS_RESOURCENAME=:DWS_RESOURCENAME,");
            strSql.Append("DWS_RESOURCESTATUS=:DWS_RESOURCESTATUS,");
            strSql.Append("RECORDTIME=:RECORDTIME,");
            strSql.Append("DWS_REMARK=:DWS_REMARK,");
            strSql.Append("DWS_IP=:DWS_IP,");
            strSql.Append("DWS_DEPARTMENT=:DWS_DEPARTMENT,");
            strSql.Append("DWS_DESCRIPTION=:DWS_DESCRIPTION");
            strSql.Append(" where DWS_RESOURCEID=:DWS_RESOURCEID and DWS_RESOURCENAME=:DWS_RESOURCENAME and DWS_RESOURCESTATUS=:DWS_RESOURCESTATUS and RECORDTIME=:RECORDTIME and DWS_REMARK=:DWS_REMARK and DWS_IP=:DWS_IP and DWS_DEPARTMENT=:DWS_DEPARTMENT and DWS_DESCRIPTION=:DWS_DESCRIPTION ");
            OracleParameter[] parameters = {
					new OracleParameter(":DWS_RESOURCEID", OracleType.VarChar,100),
					new OracleParameter(":DWS_RESOURCENAME", OracleType.VarChar,800),
					new OracleParameter(":DWS_RESOURCESTATUS", OracleType.VarChar,10),
					new OracleParameter(":RECORDTIME", OracleType.DateTime),
					new OracleParameter(":DWS_REMARK", OracleType.VarChar,800),
					new OracleParameter(":DWS_IP", OracleType.VarChar,30),
					new OracleParameter(":DWS_DEPARTMENT", OracleType.VarChar,800),
					new OracleParameter(":DWS_DESCRIPTION", OracleType.VarChar,800)};
            parameters[0].Value = model.DWS_RESOURCEID;
            parameters[1].Value = model.DWS_RESOURCENAME;
            parameters[2].Value = model.DWS_RESOURCESTATUS;
            parameters[3].Value = model.RECORDTIME;
            parameters[4].Value = model.DWS_REMARK;
            parameters[5].Value = model.DWS_IP;
            parameters[6].Value = model.DWS_DEPARTMENT;
            parameters[7].Value = model.DWS_DESCRIPTION;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string DWS_RESOURCEID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DWS_RESOURCEITEM_INFO ");
            strSql.Append(" where DWS_RESOURCEID=:DWS_RESOURCEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":DWS_RESOURCEID", OracleType.VarChar,50)};
            parameters[0].Value = DWS_RESOURCEID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Common.DWS_RESOURCEITEM_INFO GetModel(string DWS_RESOURCEID, DateTime RECORDTIME)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DWS_RESOURCEID,DWS_RESOURCENAME,DWS_RESOURCESTATUS,RECORDTIME,DWS_REMARK,DWS_IP,DWS_DEPARTMENT,DWS_DESCRIPTION");
            strSql.Append(" from DWS_RESOURCEITEM_INFO ");
            strSql.Append(" where DWS_RESOURCEID=:DWS_RESOURCEID and RECORDTIME=:RECORDTIME ");
            OracleParameter[] parameters = {
					new OracleParameter(":DWS_RESOURCEID", OracleType.VarChar,50),
					new OracleParameter(":RECORDTIME", OracleType.DateTime)};
            parameters[0].Value = DWS_RESOURCEID;
            parameters[1].Value = RECORDTIME;

            Model.Common.DWS_RESOURCEITEM_INFO model = new Model.Common.DWS_RESOURCEITEM_INFO();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.DWS_RESOURCEID = ds.Tables[0].Rows[0]["DWS_RESOURCEID"].ToString();
                model.DWS_RESOURCENAME = ds.Tables[0].Rows[0]["DWS_RESOURCENAME"].ToString();
                model.DWS_RESOURCESTATUS = ds.Tables[0].Rows[0]["DWS_RESOURCESTATUS"].ToString();
                if (ds.Tables[0].Rows[0]["RECORDTIME"].ToString() != "")
                {
                    model.RECORDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["RECORDTIME"].ToString());
                }
                model.DWS_REMARK = ds.Tables[0].Rows[0]["DWS_REMARK"].ToString();
                model.DWS_IP = ds.Tables[0].Rows[0]["DWS_IP"].ToString();
                model.DWS_DEPARTMENT = ds.Tables[0].Rows[0]["DWS_DEPARTMENT"].ToString();
                model.DWS_DESCRIPTION = ds.Tables[0].Rows[0]["DWS_DESCRIPTION"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DWS_RESOURCEID,DWS_RESOURCENAME,DWS_RESOURCESTATUS,RECORDTIME,DWS_REMARK,DWS_IP,DWS_DEPARTMENT,DWS_DESCRIPTION ");
            strSql.Append(" FROM DWS_RESOURCEITEM_INFO ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by DWS_RESOURCEID,DWS_RESOURCENAME ");
            return OracleHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListInfo()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DWS_RESOURCEID,DWS_RESOURCENAME,case DWS_RESOURCESTATUS when 'Y' then  '正常'  when 'N' then '异常' else '不可用' end  as DWS_RESOURCESTATUS,RECORDTIME,DWS_REMARK,DWS_IP,DWS_DEPARTMENT,DWS_DESCRIPTION ");
            strSql.Append(" FROM DWS_RESOURCEITEM_INFO ");
            strSql.Append(" order by DWS_RESOURCEID,DWS_RESOURCENAME ");
            return OracleHelper.Query(strSql.ToString());
        }
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "DWS_RESOURCEITEM_INFO";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}


